/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.impl;

import com.qdu.dao.BookinformationDao;
import com.qdu.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author SBH
 */
public class BookinformationImpl implements BookinformationDao {

    @Override
    public List getBookInfo(int book_id) {

        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List list = new ArrayList();


        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select * from bookinformation where book_id=?");
             ps.setInt(1, book_id);
            rs = ps.executeQuery();
            con.commit();
            while (rs.next()) {
                list.add(rs.getString(1));
                list.add(rs.getString(2));
                list.add(rs.getString(3));
                list.add(rs.getString(4));
                list.add(rs.getString(5));
                list.add(rs.getString(6));
                list.add(rs.getString(7));
                list.add(rs.getString(8));
                list.add(rs.getString(9));
                list.add(rs.getString(10));
                

            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return list;

    }

    @Override
    public List getOrder(String bookorderform_formnumber) {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List list = new ArrayList();
        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select bookinformation.book_name,bookorderform.bookorderform_amount,bookinformation.book_price,bookinformation.book_discountok,bookinformation.book_id from bookinformation,bookorderform where bookinformation.book_id=bookorderform.bookorderform_bookid and bookorderform.bookorderform_formnumber=?");
            ps.setString(1,bookorderform_formnumber );
            rs = ps.executeQuery();
            con.commit();
            while (rs.next()) {
                 List list2 = new ArrayList();
                list2.add(rs.getString(1));
                list2.add(rs.getString(2));
                list2.add(rs.getString(3));
                list2.add(rs.getString(4));
                list2.add(rs.getString(5));
                list.add(list2);
                

            }

            return list;
        } catch (Exception e) {
            e.printStackTrace();
            return list;
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }


    }

}
